using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using Crimson;
using Crimson.Module;

public partial class Admin_Crimson_Controls_InfoList : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData(InfoManager.DaoFactory.InfoDao.FindAll(0, GridView1.PageSize));
        }
    }

    private void BindData(IList<Info> data)
    {
        GridView1.DataSource = data;
        GridView1.DataBind();
    }

    protected void pageIndexChanged(object sender, EventArgs e)
    {
        var gridView = (GridView)sender;

        IList<Info> datas = InfoManager.DaoFactory.InfoDao.FindAll(gridView.PageIndex, gridView.PageSize);

        BindData(datas);
    }

    protected void DeleteSelected(object sender, EventArgs e)
    {
        foreach (GridViewRow item in GridView1.Rows)
        {
            var checkbox = (System.Web.UI.HtmlControls.HtmlInputCheckBox)item.Cells[0].FindControl("CheckBox1");
            if (checkbox.Checked)
            {
                InfoManager.Delete(new Guid(checkbox.Value));
            }
        }
        BindData(InfoManager.DaoFactory.InfoDao.FindAll(0, GridView1.PageSize));
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (HiddentSelectedTypeId.Value.Length != 0)
        {
            var list = InfoManager.DaoFactory.InfoDao.Find(new Guid(HiddentSelectedTypeId.Value), 0, GridView1.PageSize,
                                                           true, InfoState.Draft | InfoState.Published);
            BindData(list);
        }
        else
            InfoManager.DaoFactory.InfoDao.FindAll(0, GridView1.PageSize);
    }
}